package com.persondemo.videoappliction.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.persondemo.videoappliction.R;
import com.persondemo.videoappliction.bean.DuanziBean;
import com.persondemo.videoappliction.bean.VipSeachBean;
import com.persondemo.videoappliction.utils.ImageLoaderUtil;

import java.util.List;

import fm.jiecao.jcvideoplayer_lib.JCUserAction;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;

/**
 * Created by Administrator on 2018/4/19.
 */

public class DuanzIDitlsAdapter extends BaseMultiItemQuickAdapter<DuanziBean.DataBean, BaseViewHolder> {
    private Context mContext;

    public DuanzIDitlsAdapter(List<DuanziBean.DataBean> data, Context mContext) {
        super(data);
        this.mContext = mContext;
        addItemType(DuanziBean.DataBean.types_01, R.layout.item_duanzi_01);
        addItemType(DuanziBean.DataBean.types_02, R.layout.item_duanzi_04);
        addItemType(DuanziBean.DataBean.types_03, R.layout.item_duanzi_02);
    }

    @Override
    protected void convert(BaseViewHolder helper, DuanziBean.DataBean item) {
        switch (helper.getItemViewType()) {
            case DuanziBean.DataBean.types_01://图文
                helper.setText(R.id.base_dianzan,item.getSupport()+"");
                helper.setText(R.id.base_cai,item.getOpposition()+"");
                helper.setText(R.id.base_collect,item.getShou()+"");
                helper.setText(R.id.base_pinglun,item.getPing()+"");

                if (!TextUtils.isEmpty(item.getUsername())) {
                    helper.setText(R.id.duanzi_name_01, item.getUsername());
                }
                helper.setText(R.id.duanzi_comment, "    "+item.getContent());
                helper.setText(R.id.duanzi_time_01, item.getTime());
                ImageLoaderUtil.LoadImagelarge(mContext, item.getAvatar(), helper.getView(R.id.duanzi_img_head_01));
                if (item.getImgs() != null && item.getImgs().size() > 0) {
                    ImageLoaderUtil.LoadImage(mContext, item.getImgs().get(0), helper.getView(R.id.duanzi_img_01));
                }
                helper.addOnClickListener(R.id.item_duanzi_liner);
                helper.addOnClickListener(R.id.dianzan_liner);
                helper.addOnClickListener(R.id.cai_liner);
                helper.addOnClickListener(R.id.collect_liner);
                helper.addOnClickListener(R.id.comment_liner);
                break;
            case DuanziBean.DataBean.types_02://视频
                helper.setText(R.id.base_dianzan,item.getSupport()+"");
                helper.setText(R.id.base_cai,item.getOpposition()+"");
                helper.setText(R.id.base_collect,item.getShou()+"");
                helper.setText(R.id.base_pinglun,item.getPing()+"");
                ImageLoaderUtil.LoadImagelarge(mContext, item.getAvatar(), helper.getView(R.id.duanzi_img_head_04));
                helper.setText(R.id.duanzi_name_04, item.getUsername());
                helper.setText(R.id.duanzi_time_04, item.getTime());
                JCVideoPlayerStandard jcVideoPlayer = helper.getView(R.id.videoplayer);
                jcVideoPlayer.setUp(item.getVideo()
                        , JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL, item.getContent());
                JCVideoPlayer.setJcUserAction(new JCUserAction() {
                    @Override
                    public void onEvent(int type, String s, int i1, Object... objects) {
                        switch (type) {
                            case JCUserAction.ON_CLICK_START_ICON:
                                helper.getView(R.id.tv_videoduration).setVisibility(View.GONE);
                                break;
                        }
                    }
                });
                helper.addOnClickListener(R.id.dianzan_liner);
                helper.addOnClickListener(R.id.cai_liner);
                helper.addOnClickListener(R.id.collect_liner);
                helper.addOnClickListener(R.id.comment_liner);
                ImageLoaderUtil.LoadImage(mContext, item.getVideo_img(), jcVideoPlayer.thumbImageView);
                break;
            case DuanziBean.DataBean.types_03:
                helper.setText(R.id.base_dianzan,item.getSupport()+"");
                helper.setText(R.id.base_cai,item.getOpposition()+"");
                helper.setText(R.id.base_collect,item.getShou()+"");
                helper.setText(R.id.base_pinglun,item.getPing()+"");
                ImageLoaderUtil.LoadImagelarge(mContext, item.getAvatar(), helper.getView(R.id.duanzi_img_head_02));
                helper.setText(R.id.duanzi_name_02, item.getUsername());
                helper.setText(R.id.duanzi_time_02, item.getTime());
                helper.setText(R.id.duanzi_comment, "    "+ item.getContent());
                helper.addOnClickListener(R.id.dianzan_liner);
                helper.addOnClickListener(R.id.cai_liner);
                helper.addOnClickListener(R.id.collect_liner);
                helper.addOnClickListener(R.id.comment_liner);
                break;
        }
    }

}
